<?php

// *** Documentation
/*______________________________________________________________________________

CEO Ace Test: Invalid User

Last Update: Sep 2007
Author: Tom at klenwell@gmail.com

SUMMARY
  Test an invalid user in Ace Framework

NOTES
		
______________________________________________________________________________*/


// *** Pre-Script (core settings, includes)
/*____________________________________________________________________________*/

// ** Core Page Settings

  // start script timer
  $_PAGE['tx1'] = microtime();

	// Page ID (used as DOM id for template page tags below)
	$_PAGE['id'] = 'page_scriptframe';

	// Meta Data (used in Head section below)
	$_PAGE['title'] = 'Klenwell Page Template';
	$_PAGE['keywords'] = 'klenwell, PHP, XHTML, CSS';
	$_PAGE['description'] = 'a well-structured script template for XHTML pages created using the AMVC v.3 framework';

	
// ** Load Framework

  // debug settings
  $ceo_debug = 0;
  $ace_debug = 0;
	
	// Call Driver (use dirname or ../ to locate directory)
	$_PATH['project_driver'] = '../www/ceo.project_driver.inc.php';
	require_once($_PATH['project_driver']);
	
  // Create Framework Object and Load
  $Ceo = new CeoFramework($ceo_debug);
  $Ceo->filter_trivial = 1;
  $Ceo->load_framework();
  $Ceo->print_d('framework load time: ' . $Ceo->tx_diff($_PAGE['tx1']));
  
  // Load Extensions
  $Ceo->debug = $ace_debug;
  $Ceo->load_ext('ace');
  $Ceo->Ace->print_d('ACE is loaded!', 'lime');
  
  // load database
  $test_db = 'ace_test';
  $Ceo->e("manually loading db [$test_db] for ace -- need to auto this", E_USER_WARNING);
  $Ceo->Ace->Dbo->connect($test_db, 'root', 'root');
  
  // Restrict Access
  $Ceo->Ace->session_length = 60;
  $has_access = $Ceo->Ace->restrict_access_below(1);
  $Ceo->debug = $ceo_debug;

  // Include Additional Files
  
  // Debug
  if ( $has_access )
  {
    $age = time() - $Ceo->Ace->USER['login_uts'];
    $time_left = $Ceo->Ace->session_length - $age;
    $Ceo->print_d("<h3>you are now looking at restricted content ($time_left s left in session)</h3>", 'green');
    print $Ceo->Ace->print_status_block('form');
  }
  else
  {
    $Ceo->print_d("<h3>you do not have access (but can still see the page if lockout is still in dev)</h3>", 'red');
    
    if ( $Ceo->Ace->USER['is_logged_in'] )
    {
      $Ceo->print_d('resetting user/session now', 'magenta');
      $Ceo->Ace->_reset_user();
    }
  }
  
/*============================================================================*/



// *** Data (triggers, flags, HTML, and other variables)
/*____________________________________________________________________________*/

// ** Controller Flags

	// Triggers (Page Events)
	$_TRIGGER['event'] = 0;
	
	// Flags
	$_FLAG['generic'] = 0;
	
	// Show
	$_SHOW['block'] = 0;
	
// ** Modules

	// File Paths
	$_MOD['name'] = '';
	

// ** Data Declarations
	

// ** Output
	
	// Head (core)
	$_HEAD['doc_title'] = $_PAGE['title'];
  $_HEAD['keywords'] = $_PAGE['keywords'];
  $_HEAD['description'] = $_PAGE['description'];
	
	// Head (extended)
  $_HEAD['favicon'] = 'http://firefox.no/favicon.ico';
  $_HEAD['css_link'] = '';
  $_HEAD['js_link'] = '';
	
	// Static HTML
	$_HTML['favicon'] = '';
	$_HTML['firefox_tag'] = '<a href="http://www.spreadfirefox.com/?q=affiliates&amp;id=151890&amp;t=85"><img border="0" alt="Get Firefox!" title="Get Firefox!" src="http://sfx-images.mozilla.org/affiliates/Buttons/80x15/firefox_80x15.png"/></a>';
	$_HTML['copyright'] = '<span class="copyright">some rights reserved, &#169; ' . date('Y') . '</span>';
	$_HTML['sitename'] = '<span class="sitename">' . $_SERVER['HTTP_HOST'] . '</span>';

	// Dynamic HTML
  $_HTML['dyn'] = '';
	
	// Page Panels
	$_PAGE['masthead'] = '';
	$_PAGE['core'] = '<div class="core_panel" style="color:#eee;">.</div>';
	$_PAGE['footer'] = '<div class="footer_panel">' . $_HTML['firefox_tag'] . '</div>';

/*============================================================================*/



// *** Controllers (handles requests and sets event triggers)
/*____________________________________________________________________________*/

// ** Default
$_TRIGGER['form_module'] = 0;

// ** GET-triggered Requests

// ** POST-triggered Requests

// ** COOKIE-triggered Requests

/*============================================================================*/



// *** Events (trigger-controlled events)
/*____________________________________________________________________________*/

/*============================================================================*/



// *** Output (set page head, dynamic HTML, blocks, and stacks for web page template)
/*____________________________________________________________________________*/

// ** HTML Blocks

  // Metabar
  $_HTML['metabar'] = <<<HTML
<div id="metabar_panel">
metabar panel
</div>
HTML;


// ** Page Blocks

  // Core
  $_PAGE['core'] = <<<HTML
<div id="core_panel">
core panel
</div>
HTML;

	// Masthead
	$_PAGE['masthead'] = <<<HTML
<div id="masthead_panel">
{$_HTML['metabar']}
masthead panel
</div>
HTML;

	// Footer
	$_PAGE['footer'] = <<<HTML
<div id="footer_panel">
<div id="footer_left">{$_HTML['sitename']}</div>
<div id="footer_right">{$_HTML['firefox_tag']}</div>
{$_HTML['copyright']}
</div>
HTML;


// ** Head Tags (echoed below)
	
	// Head Extensions (favicon, CSS, JS)
	$_HTML['favicon'] = $Ceo->add_favicon($_HEAD['favicon']);
	#$_HTML['css'] = amvc_add_css_link($_HEAD['css_link']);
  #$_HTML['js'] = amvc_add_js_link($_HEAD['js_link']);

/*============================================================================*/



// *** HTML Template (what the viewer will see in her browser)
/*____________________________________________________________________________*/

// Dump Head Core
$Ceo->print_head();

// Dump Head Extensions
print $_HTML['favicon'];
print $_HTML['css'];
print $_HTML['js'];

// ** Escape from PHP (starring Snake PHPliskin)
?>

<!-- internal style sheet -->
<style type="text/css">

/* BASIC LAYOUT */
body
{
 margin:0; padding:0;
 font-family:Arial, Helvetica, sans-serif;
 background:#f3f3ff;
}
.page
{
 width:auto;
 margin:0; padding:2px;
 background:white;
}
a { color:#666; }
a:hover { color:lime; text-decoration:none; }

/* FOOTER PANEL */
#footer_panel
{
 width:auto; clear:both;
 margin-top:4px; padding:4px;
 text-align:center;
 font:11px/1.4em Verdana, Geneva, sans-serif;
 border-top:1px solid #f3f3ff;
}
#footer_left { float:left; }
#footer_right { float:right; }

</style>
<!-- end internal style sheet -->

</head>
<!-- *** END DOCUMENT HEAD *** -->

<!-- *** START BODY *** -->
<body>

<!-- PAGE -->
<div class="page" id="<?php echo $_PAGE['id']; ?>">

<?php print $_PAGE['masthead']; ?>

<?php print $_PAGE['core']; ?>

<?php $Ceo->Ace->dump(); ?>

<?php print $_PAGE['footer']; ?>

</div>	
<!-- end PAGE -->

<?php 
// ** Return to PHP 
/*============================================================================*/



// *** Post-Script (close HTML, flush buffer, and other backend operations)
/*____________________________________________________________________________*/

// ** Close HTML
#$Ceo->close_html();
echo "\n<!-- Close HTML -->\n</body>\n</html>\n";

// ** Flush Buffer
#$Ceo->flush_buffer();
while (ob_get_level() > 0) { ob_end_flush(); }
flush();
echo "<!-- buffer flushed at " . date('r') . " -->";

// ** Page Timer
#$Ceo->print_page_timer();
$_tx2 = microtime();
$_tx3 = number_format(((substr($_tx2,0,9)) + (substr($_tx2,-10)) - (substr($_PAGE['tx1'],0,9)) - (substr($_PAGE['tx1'],-10))),4); 
echo "\n<!-- script [id: {$_PAGE['id']}] generated in $_tx3 s -->";

/*============================================================================*/
// * That's All Folks!
?>
